// Grozi Ties
// David Ing and Jae Shin Woo
//
// This is a program meant to test the X/Y coordinates of mouse
//----------------------------------------------------------------

"localhost" => string hostname; 
7000 => int port;  // port that it sends to

// sends packet
if( me.args() ) me.arg(0) => hostname;
if( me.args() > 1 ) me.arg(1) => Std.atoi => port;
OscSend xmit;

// sets the hose name at the given port
xmit.setHost( hostname, port );

Hid hi; 
0 => int cont;
0 => int a;
HidMsg msg;
0 => int device; 

// connects to mouse 
if( me.args() ) me.arg(0) => Std.atoi => device;
if( !hi.openMouse( device ) ) me.exit();

// variables to keep track of x and y positions
0 => int Xpos;
0 => int Ypos;

while( true ){
    hi => now;
    while( hi.recv( msg ) ){
        // keeps track of change in x and y position
        Xpos + msg.deltaX => Xpos;
        Ypos + msg.deltaY => Ypos;

        <<<msg.deltaY>>>;
        <<<"SECONDX:  " + Xpos>>>;
        <<<"SECONDY:  " + Ypos>>>;
        //if( msg.isMouseMotion() ){
        if(msg.isButtonDown()){
            Xpos - 1 => Xpos;  // compensates for the button click
            // send the X
                <<< "SENDINGX: ", Xpos  >>>;
                xmit.startMsg("/edge","i");
                cont + 1 => cont;
                if(cont==1){
                    0 => cont;
                    <<<"SSS">>>;
		    (Xpos/10) =>xmit.addInt; 
                }
            // send the Y
     //           <<< "SENDINGY: ", Ypos  >>>;
      //          xmit.startMsg("/edge2","i");

      //          cont => cont;
       //         if(cont==1){
                    0 => cont;
       //             <<<"SSS">>>; 
                
           // }
       // 0.2::second => now;

        }
    }
}
